﻿using de.wolfmarco.pas.Client.MVVM;
using de.wolfmarco.pas.Shared.Interfaces;
using de.wolfmarco.pas.Shared.MVVM;
using de.wolfmarco.pas.Shared.Regions;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;

namespace de.wolfmarco.pas.Client.Modules
{
    public class StartMenuModule : IModule
    {
        protected readonly RegionManager regionManager;
        protected readonly IUnityContainer container;
        protected readonly IModuleManager moduleManager;

        public StartMenuModule( RegionManager regionManager, IUnityContainer container, IModuleManager moduleManager )
        {
            this.regionManager = regionManager;
            this.container = container;
            this.moduleManager = moduleManager;
        }

        public void Initialize()
        {
            TransientLifetimeManager transientLifetimeManager = new TransientLifetimeManager();
            StartMenuModuleViewModel viewModel = container.Resolve<StartMenuModuleViewModel>();

            container.RegisterInstance<ModuleViewModel>("StartMenu", viewModel);

            InjectionMember[] injectionMember = new InjectionMember[]
            {
                new InjectionProperty( "DataContext", viewModel )
            };
            container.RegisterType( typeof( object ), typeof( StartMenuModuleView ), ClientHelper.StartMenuModuleView, transientLifetimeManager, injectionMember );
            regionManager.RegisterViewWithRegion(RegionNames.ModuleRegion, () => container.Resolve<StartMenuModuleView>(ClientHelper.StartMenuModuleView));
        }
    }
}
